const char * username,
char * err_msg);
siridb_user_t * siridb_users_get_user(
- llist_t * users,
+ siridb_t * siridb,
const char * username,
const char * password);
int siridb_users_save(siridb_t * siridb);
}
if ((user = siridb_users_get_user(
- siridb->users,
+ siridb,
username,
password)) == NULL)
{
char name[user_node->len - 1];
strx_extract_string(name, user_node->str, user_node->len);
- if ((user = siridb_users_get_user(siridb->users, name, NULL)) == NULL)
+ if ((user = siridb_users_get_user(siridb, name, NULL)) == NULL)
{
snprintf(query->err_msg,
SIRIDB_MAX_SIZE_ERR_MSG,
char username[user_node->len - 1];
strx_extract_string(username, user_node->str, user_node->len);
- if ((user = siridb_users_get_user(siridb->users, username, NULL)) == NULL)
+ if ((user = siridb_users_get_user(siridb, username, NULL)) == NULL)
{
snprintf(query->err_msg, SIRIDB_MAX_SIZE_ERR_MSG,
"Cannot find user: '%s'", username);
char username[user_node->len - 1];
strx_extract_string(username, user_node->str, user_node->len);
- if ((user = siridb_users_get_user(siridb->users, username, NULL)) == NULL)
+ if ((user = siridb_users_get_user(siridb, username, NULL)) == NULL)
{
snprintf(query->err_msg,
SIRIDB_MAX_SIZE_ERR_MSG,
if (strlen(password) < SIRIDB_MIN_PASSWORD_LEN)
{
- sprintf(err_msg, "Password should be at least %d characters.",
- SIRIDB_MIN_PASSWORD_LEN);
+ if (err_msg != NULL)
+ {
+ sprintf(err_msg,
+ "Password should be at least %d characters.",
+ SIRIDB_MIN_PASSWORD_LEN);
+ }
return -1;
}
if (strlen(password) > SIRIDB_MAX_PASSWORD_LEN)
{
- sprintf(err_msg, "Password should be at most %d characters.",
- SIRIDB_MAX_PASSWORD_LEN);
+ if (err_msg != NULL)
+ {
+ sprintf(err_msg,
+ "Password should be at most %d characters.",
+ SIRIDB_MAX_PASSWORD_LEN);
+ }
return -1;
}
if (!strx_is_graph(password))
{
- sprintf(err_msg,
- "Password contains illegal characters. (only graphical "
- "characters are allowed, no spaces, tabs etc.)");
+ if (err_msg != NULL)
+ {
+ sprintf(err_msg,
+ "Password contains illegal characters. (only graphical "
+ "characters are allowed, no spaces, tabs etc.)");
+ }
return -1;
}
return 1;
}
- if (siridb_users_get_user(siridb->users, name, NULL) != NULL)
+ if (siridb_users_get_user(siridb, name, NULL) != NULL)
{
snprintf(err_msg,
SIRIDB_MAX_SIZE_ERR_MSG,
* the user will be returned when found.
*/
siridb_user_t * siridb_users_get_user(
- llist_t * users,
+ siridb_t * siridb,
const char * name,
const char * password)
{
+ llist_t * users = siridb->users;
siridb_user_t * user;
char pw[OWCRYPT_SZ];
struct crypt_data fallback_data;
#endif
-
if ((user = llist_get(
users,
(llist_cb) USERS_cmp,
/* Required for compatibility with version < 2.0.14 */
else if (user->password[0] == '$')
{
+ /* this will migrate as soon as a user logs in */
+ _Bool is_valid;
fallback_data.initialized = 0;
fallback_pw = crypt_r(password, user->password, &fallback_data);
- return (strcmp(fallback_pw, user->password) == 0) ? user : NULL;
+ is_valid = strcmp(fallback_pw, user->password) == 0;
+ (void) (is_valid && \
+ siridb_user_set_password(user, password, NULL) == 0 && \
+ siridb_users_save(siridb));
+ return is_valid ? user : NULL;
}
#endif
return NULL;